package com.ruoyi.project.channel.channelScore.controller;

import java.util.List;

import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.channelScore.domain.ChannelScore;
import com.ruoyi.project.channel.channelScore.service.IChannelScoreService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 跑分码商信息操作处理
 * 
 * @author CAIN
 * @date 2019-10-21
 */
@Controller
@RequestMapping("/channel/channelScore")
public class ChannelScoreController extends BaseController
{
    private String prefix = "channel/channelScore";
	
	@Autowired
	private IChannelScoreService channelScoreService;
	
	@RequiresPermissions("channel:channelScore:view")
	@GetMapping()
	public String channelScore()
	{
	    return prefix + "/channelScore";
	}
	
	/**
	 * 查询跑分码商列表
	 */
	@RequiresPermissions("channel:channelScore:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ChannelScore channelScore)
	{
		startPage();
        List<ChannelScore> list = channelScoreService.selectChannelScoreList(channelScore);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出跑分码商列表
	 */
	@RequiresPermissions("channel:channelScore:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChannelScore channelScore)
    {
    	List<ChannelScore> list = channelScoreService.selectChannelScoreList(channelScore);
        ExcelUtil<ChannelScore> util = new ExcelUtil<ChannelScore>(ChannelScore.class);
        return util.exportExcel(list, "channelScore");
    }
	
	/**
	 * 新增跑分码商
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存跑分码商
	 */
	@RequiresPermissions("channel:channelScore:add")
	@Log(title = "跑分码商", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(User user, ChannelScore channelScore)
	{		
		return channelScoreService.insertChannelScore(channelScore,user);
	}

	/**
	 * 修改跑分码商
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
	{
		ChannelScore channelScore = channelScoreService.selectChannelScoreById(userId);
		mmap.put("channelScore", channelScore);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存跑分码商
	 */
	@RequiresPermissions("channel:channelScore:edit")
	@Log(title = "跑分码商", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(User user, ChannelScore channelScore)
	{		
		return channelScoreService.updateChannelScore(channelScore,user);
	}
	
	/**
	 * 删除跑分码商
	 */
	@RequiresPermissions("channel:channelScore:remove")
	@Log(title = "跑分码商", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(channelScoreService.deleteChannelScoreByIds(ids));
	}
	
}
